package com.zhongyu.consumer.controller;

import com.zhongyu.comm.vo.DetailVo;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/detail")
public class DetailController2 {

    @Resource
    private RestTemplate restTemplate;

    /*@Resource
    private LoadBalancerClient loadBalancerClient;*/

    @GetMapping("/query2")
    public List<DetailVo> query(){
       /* ServiceInstance serviceInstance = loadBalancerClient.choose("news-provider");
        String url=serviceInstance.getUri()+"/detail/searchAll";
        */
       String url="http://news-provider/detail/searchAll";
        List<DetailVo> list = restTemplate.getForObject(url,List.class);
        return list;
    }


}
